﻿using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Text;

using Weazel.Willows;

namespace WillowsConsole
{
	class Program
	{
		private static void printUsage()
		{
			Console.WriteLine("usage: willows configuration.xml");
			Console.WriteLine();
			Console.WriteLine("This tool requires an XML configuration file to be specified.");
			Console.WriteLine("Please consult the documentation for a description of the");
			Console.WriteLine("configuration file format.");
		}

		static void Main(string[] args)
		{
			Console.WriteLine("Willows System Compiler - Development version");
			Console.WriteLine();

			if (args.Length != 1 || !File.Exists(args[0]))
			{
				printUsage();
				return;
			}

			SystemGenerator generator = new SystemGenerator();

			if (!generator.Run(args[0]))
			{
				// one or more errors encountered
				if (generator.ConfigurationErrors.Count > 0)
				{
					Console.WriteLine("Error(s) encountered during setup and configuration:");
					Console.WriteLine();

					foreach (Weazel.Willows.ConfigurationError error in generator.ConfigurationErrors)
						Console.WriteLine(error.ErrorMessage + "\n");
				}
				else if (generator.ModelErrors.Count > 0)
				{
					Console.WriteLine("Error(s) encountered while building Model:");
					Console.WriteLine();

					foreach (Weazel.Willows.ModelError error in generator.ModelErrors)
						Console.WriteLine(error.ErrorMessage + "\n");
				}
			}
		}
	}
}
